package com.wy.Service.impl;

import com.wy.Service.CompanyService;
import com.wy.dao.CompanyDao;
import com.wy.pojo.Company;
import com.wy.vo.CompanyDto;
import com.wy.vo.PageVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
public class CompanyServiceImpl extends BaseServiceImpl implements CompanyService {
    @Resource
    private CompanyDao companyDao;

    @Override
    public List<Company> findAll() {
        return companyDao.findAll();
    }

    @Override
    public void add(Company company) {
        companyDao.save(company);
    }

    @Override
    public void delete(Integer id) {
        companyDao.deleteById(id);
    }

    @Override
    public List<Company> findBId(Integer id) {
        return companyDao.findBId(id);
    }

    @Override
    public void update(Company company) {
        companyDao.save(company);
    }

    @Override
    public PageVo searchPage(Integer current, Integer pageSize, CompanyDto dto) {
        StringBuilder sbd=new StringBuilder("select r from Company r  where 1=1 ");
        if(!StringUtils.isEmpty(dto.getName())){
            sbd.append(" and r.name like :name");
            dto.setName("%"+dto.getName()+"%");
        }
        return super.searchPagination(current,pageSize,sbd.toString(),dto);
    }
}
